#{extends 'mobile_main.html' /}
#{set title:'扫描' /}
<script src="http://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
<script>
    wx.config({
        debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
        appId: '${jsonObject?.getString("appId")}', // 必填，公众号的唯一标识
        timestamp:'${jsonObject?.getString("timestamp")}' , // 必填，生成签名的时间戳
        nonceStr: '${jsonObject?.getString("nonceStr")}', // 必填，生成签名的随机串
        signature: '${jsonObject?.getString("signature")}',// 必填，签名
        jsApiList: ['scanQRCode'] // 必填，需要使用的JS接口列表
    });
</script>
<!-- 标题栏 -->
<header class="bar bar-nav">
    <a class="icon icon-me pull-left open-panel"></a>
    <h1 class="title">扫描</h1>
</header>
<!-- 工具栏 -->
<nav class="bar bar-tab">
    <a class="tab-item external active">
        <span class="icon icon-code"></span>
        <span class="tab-label">扫描</span>
    </a>
    <a class="tab-item external" href="/WxController/mine">
        <span class="icon icon-me"></span>
        <span class="tab-label">我的</span>
    </a>
</nav>
<!-- 这里是页面内容区 -->
<div class="content">
    <div class="content-block">
        <div class="row">
            <div class="col-33"><a href="#" id="scan0" class="button button-big button-fill button-danger">扫描</a></div>
            <div class="col-33"><a href="#" id="getOrderInfo" class="button button-big button-fill button-warning">获取信息</a></div>
            <div class="col-33"><a href="#" id="submit0" class="button button-big button-fill button-success">提交</a></div>
        </div>
    </div>
    <div class="list-block">
        <ul>
            <li>
                <div class="item-content">
                    <div class="item-media"><i class="icon icon-form-name"></i></div>
                    <div class="item-inner">
                        <div class="item-title label">快递单号</div>
                        <div class="item-input">
                            <input type="number" placeholder="" id="kddh">
                        </div>
                        *{<span class="icon icon-code" id="scan0"></span>}*
                    </div>
                </div>
            </li>
            <li>
                <div class="item-content">
                    <div class="item-media"><i class="icon icon-form-calendar"></i></div>
                    <div class="item-inner">
                        <div class="item-title label">车辆脚垫信息</div>
                        <div class="item-input">
                            <textarea id="cljdxx"></textarea>
                        </div>
                    </div>
                </div>
            </li>
            <li>
                <div class="item-content">
                    <div class="item-media"><i class="icon icon-form-email"></i></div>
                    <div class="item-inner">
                        <div class="item-title label">客户姓名</div>
                        <div class="item-input">
                            <input type="text" placeholder="" id="xm">
                        </div>
                    </div>
                </div>
            </li>
            <li>
                <div class="item-content">
                    <div class="item-media"><i class="icon icon-form-password"></i></div>
                    <div class="item-inner">
                        <div class="item-title label">手机号</div>
                        <div class="item-input">
                            <input type="text" placeholder="" class="" id="sjh">
                        </div>
                    </div>
                </div>
            </li>
            <li class="align-top">
                <div class="item-content">
                    <div class="item-media"><i class="icon icon-form-comment"></i></div>
                    <div class="item-inner">
                        <div class="item-title label">邮寄详细地址</div>
                        <div class="item-input">
                            <textarea id="yjxxdz"></textarea>
                        </div>
                    </div>
                </div>
            </li>
            <li>
                <div class="item-content">
                    <div class="item-media"><i class="icon icon-form-gender"></i></div>
                    <div class="item-inner">
                        <div class="item-title label">数量</div>
                        <div class="item-input">
                            <input type="number" placeholder="" class="" id="sl">
                        </div>
                    </div>
                </div>
            </li>
            <!-- Date -->
            <li>
                <div class="item-content">
                    <div class="item-media"><i class="icon icon-form-toggle"></i></div>
                    <div class="item-inner">
                        <div class="item-title label">商户信息</div>
                        <div class="item-input">
                            <input type="text" placeholder="" class="" id="shxx">
                        </div>
                    </div>
                </div>
            </li>
            <li>
                <div class="item-content">
                    <div class="item-media"><i class="icon icon-form-gender"></i></div>
                    <div class="item-inner">
                        <div class="item-title label">制作详情</div>
                        <div class="item-input" id="zzdj">
                        </div>
                    </div>
                </div>
            </li>
            <li>
                <div class="item-content">
                    <div class="item-media"><i class="icon icon-form-gender"></i></div>
                    <div class="item-inner">
                        <div class="item-title label">备注</div>
                        <div class="item-input" id="beizhu">
                        </div>
                    </div>
                </div>
            </li>
        </ul>
    </div>
</div>
<script>
    $(function() {
        $(document).on('click', '#scan0', function () {
            wx.scanQRCode({
                needResult: 1, // 默认为0，扫描结果由微信处理，1则直接返回扫描结果，
                scanType: ["barCode"], // 可以指定扫二维码还是一维码，默认二者都有 "qrCode",
                success: function (res) {
                    var result = res.resultStr; // 当needResult 为 1 时，扫码返回的结果
                    result = result.split(',');
                    $("#kddh").val(result[1]);
                    getOrderInfo();
                }
            });
        });
        $(document).on('click', '#getOrderInfo', function () {
            getOrderInfo();
        });
        function getOrderInfo(){
            var kddh = $("#kddh").val();
            if(kddh==''){
                $.alert("快递单号不能为空")
                return false;
            }
            var user = localStorage.getItem("user");
            if(user) {
                user = JSON.parse(user);
                user = user.data;
            }
            var param = {"danhao":kddh,"uid":user.user.id,"token":user.token};
            $.ajax({
                type:"POST",                      //请求类型
                url:"/apicontroller/getOrderInfo",                 //URL
                data:param,                  //传递的参数
                dataType:"json",                 //返回的数据类型
                success:function(data){          //data就是返回的json类型的数据
                    console.log(JSON.stringify(data));
                    if(data.code=="1"){
                        $.toast("快递客单信息获取成功");
                        var order = data.data.order;
                        var orderFlow = data.data.orderFlow;

                        if(order.business_info)
                            $("#shxx").val(order.business_info);

                        $("#cljdxx").val(order.customer_car_info);
                        $("#xm").val(order.customer_name);
                        $("#sjh").val(order.customer_mobile);
                        $("#yjxxdz").val(order.customer_order_address);
                        $("#sl").val(order.count);
                        var orderExt1 = data.data.orderExt1;
                        $("#zzdj").html("工序:" + orderExt1.process_name + ",单价:"+ orderExt1.process_price + "元");

                        if(order.ext1)
                            $("#beizhu").html(order.ext1);
                    }else{
                        $.alert(data.msg);
                    }
                },
                error:function(data){
                }
            });
        }
        $(document).on('click', '#submit0', function () {
            var kddh = $("#kddh").val();
            if(kddh==''){
                $.alert("快递单号不能为空")
                return false;
            }
            var user = localStorage.getItem("user");
            if(user) {
                user = JSON.parse(user);
                user = user.data;
            }
            var param = {"danhao":kddh,"uid":user.user.id,"token":user.token};
            $.ajax({
                type:"POST",                      //请求类型
                url:"/apicontroller/submitOrder",                 //URL
                data:param,                  //传递的参数
                dataType:"json",                 //返回的数据类型
                success:function(data){          //data就是返回的json类型的数据
                    console.log(JSON.stringify(data));
                    if(data.code=="1"){
                        $.alert(data.msg, '提交成功', function () {
                            location.reload();
                        });
                    }else{
                        $.alert(data.msg);
                    }
                },
                error:function(data){
                }
            });
        })
    });
</script>